package com.jmex.model.ogredotscene.loader;

import java.io.File;
import java.io.IOException;

import com.jme.util.resource.MultiFormatResourceLocator;
import com.jme.util.resource.ResourceLocatorTool;
import com.jmex.model.ogredotscene.gen.ResourceGroup;
import com.jmex.model.ogredotscene.gen.ResourceLocation;

import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;

public class ResourceLoader {

    public void registerResourceLocation(ResourceGroup resourceGroup,File baseDir) throws MalformedURLException, IOException {
        for (ResourceLocation resourceLocation : resourceGroup.getResourceLocation()) {
            if (resourceLocation.getType().equals("FileSystem")) {
                String resourceDirName = "";
                resourceDirName = (baseDir.getCanonicalPath()+ File.separator + resourceLocation.getName() + File.separator);
                File resourceDir = new File(resourceDirName);
                MultiFormatResourceLocator resourceLocator = new MultiFormatResourceLocator(
                        resourceDir.toURI(), ".mesh", ".mesh.xml");
                resourceLocator.setTrySpecifiedFormatFirst(true);
                ResourceLocatorTool.addResourceLocator(
                        ResourceLocatorTool.TYPE_MODEL,
                        resourceLocator);
                MultiFormatResourceLocator textureLocator = new MultiFormatResourceLocator(
                        resourceDir.toURI(), ".dds", ".tga", ".png", ".jpg", ".gif",".bmp");
                resourceLocator.setTrySpecifiedFormatFirst(true);
                ResourceLocatorTool.addResourceLocator(
                        ResourceLocatorTool.TYPE_TEXTURE,
                        textureLocator);

            }
        }
    }
}
